package com.fjl.importSelector;

import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

public class MyDeferredImportSelector implements DeferredImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        System.out.println("===> MyDeferredImportSelector running...");
        boolean exists = classExists("com.example.demo.FeatureConfig");
        System.out.println("    FeatureConfig exists? " + exists);
        return exists ? new String[]{"com.example.demo.ExtraConfig"} : new String[0];
    }

    private boolean classExists(String className) {
        try {
            Class.forName(className);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }
}
